package cn.liziguo.tank.ui;

import cn.liziguo.tank.constants.ImageConst;
import com.almasb.fxgl.animation.Interpolators;
import com.almasb.fxgl.dsl.FXGL;
import com.almasb.fxgl.scene.SubScene;
import com.almasb.fxgl.texture.Texture;
import javafx.animation.TranslateTransition;
import javafx.util.Duration;

/**
 * @author Liziguo
 * @date 2022/7/16 13:50
 */
public class FailedScene extends SubScene {
    private TranslateTransition translateTransition;


    public FailedScene() {
        Texture texture = FXGL.texture(ImageConst.GAME_OVER);

        translateTransition = new TranslateTransition(Duration.seconds(2.6), texture);
        translateTransition.setFromY(FXGL.getAppHeight());
        translateTransition.setToY(FXGL.getAppHeight() / 2.0);
        translateTransition.setInterpolator(Interpolators.ELASTIC.EASE_OUT());
        translateTransition.setOnFinished(actionEvent -> {
            FXGL.getGameController().gotoGameMenu();
        });

        getContentRoot().getChildren().add(texture);
    }

    @Override
    public void onCreate() {
        translateTransition.play();
    }

}
